package com.cms.sync.service;

import java.util.List;

import com.cms.sync.model.MMSyncLog;
import com.service.AbstractDateService;
import com.utils.dbcp.ConnectionManager;
import com.utils.dbcp.ModelGenerator;

public class MMSyncLogServiceImpl extends AbstractDateService implements DefaultSyncLogService<MMSyncLog> {

	@Override
	public List<MMSyncLog> getAll() {
		String sql = "select * from t_mmsynclog";
		logger.info("[SQL] [method:getAll] ["+sql+"]");
		ModelGenerator<MMSyncLog> model = new ModelGenerator<MMSyncLog>(MMSyncLog.class);
		return model.generateList(base,sql.toString());
	}

	@Override
	public boolean save(MMSyncLog t) {
		String sql = "insert into t_mmsynclog(orderid,checkid,tradeid,price,actiontime,actionid,msisdn,feemsisdn,appid,paycode,totalprice,subsnumb,subsseq,channelid,ordertype,orderpayment,md5sign,exdata,remark,createtime) values (" +
				"'" +t.getOrderid()+"',"+
				"'" +t.getCheckid()+"',"+
				"'" +t.getTradeid()+"',"+
				t.getPrice()+","+
				"'" +t.getActiontime()+"',"+
				"'" +t.getActionid()+"',"+
				"'" +t.getMsisdn()+"',"+
				"'" +t.getFeemsisdn()+"',"+
				"'" +t.getAppid()+"',"+
				"'" +t.getPaycode()+"',"+
				t.getTotalprice()+","+
				"'" +t.getSubsnumb()+"',"+
				"'" +t.getSubsseq()+"',"+
				"'" +t.getChannelid()+"',"+
				"'" +t.getOrdertype()+"',"+
				"'" +t.getOrderpayment()+"',"+
				"'" +t.getMd5sign()+"',"+
				"'" +t.getExdata()+"',"+
				"'" +t.getRemark()+"',"+
				"'" +t.getCreatetime()+"'"+
				")";
		logger.info("[SQL] [method:save] ["+sql+"]");
		return ConnectionManager.getInstance().execute(base,sql);
	}

	@Override
	public boolean save(List<MMSyncLog> list) {
		String [] sql = new String[list.size()];
		MMSyncLog t = null;
		for(int i=0;i<list.size();i++)
		{
			t = list.get(i);
			sql[i] = "insert into t_mmsynclog(orderid,checkid,tradeid,price,actiontime,actionid,msisdn,feemsisdn,appid,paycode,totalprice,subsnumb,subsseq,channelid,ordertype,orderpayment,md5sign,exdata,remark,createtime) values (" +
					"'" +t.getOrderid()+"',"+
					"'" +t.getCheckid()+"',"+
					"'" +t.getTradeid()+"',"+
					t.getPrice()+","+
					"'" +t.getActiontime()+"',"+
					"'" +t.getActionid()+"',"+
					"'" +t.getMsisdn()+"',"+
					"'" +t.getFeemsisdn()+"',"+
					"'" +t.getAppid()+"',"+
					"'" +t.getPaycode()+"',"+
					t.getTotalprice()+","+
					"'" +t.getSubsnumb()+"',"+
					"'" +t.getSubsseq()+"',"+
					"'" +t.getChannelid()+"',"+
					"'" +t.getOrdertype()+"',"+
					"'" +t.getOrderpayment()+"',"+
					"'" +t.getMd5sign()+"',"+
					"'" +t.getExdata()+"',"+
					"'" +t.getRemark()+"',"+
					"'" +t.getCreatetime()+"'"+
					")";
		}
		logger.info("[SQL] [method:save] ["+sql+"]");
		return ConnectionManager.getInstance().executeBatch(base,sql);
	}

	@Override
	public List<MMSyncLog> idRepeatOrder(String orderId) {
		// TODO Auto-generated method stub
		return null;
	}

}
